#!/bin/bash
cd "$(dirname "$0")"
SCRIPT_DIR=$(pwd)
BUILD_DIR=$SCRIPT_DIR/build
INSTALL_DIR=$BUILD_DIR/_install

cd $INSTALL_DIR

sudo mkdir etc proc sys mnt dev tmp
sudo mkdir -p etc/init.d
cat >>$BUILD_DIR/fstab <<EOF
proc    /proc   proc    defaults        0       0
tmpfs   /tmp    tmpfs   defaults        0       0
sysfs   /sys    sysfs   defaults        0       0
EOF
sudo cp -rf $BUILD_DIR/fstab etc

cat >>$BUILD_DIR/rcS <<EOF
echo "Welcome to linux..."
mount -t proc proc /proc
mount sysfs /sys -t sysfs
EOF
sudo cp -rf $BUILD_DIR/rcS etc/init.d
sudo chmod 755 etc/init.d/rcS

cat >>$BUILD_DIR/inittab <<EOF
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
EOF

sudo cp -rf $BUILD_DIR/inittab etc
sudo chmod 755 etc/inittab

cd dev
sudo mknod console c 5 1
sudo mknod null c 1 3
sudo mknod tty1 c 4 1
sudo chown -R root:root $INSTALL_DIR